package com.atguigu.newstestdemo.service.impl;

import com.atguigu.newstestdemo.entity.User;
import com.atguigu.newstestdemo.mapper.UserMapper;
import com.atguigu.newstestdemo.service.UserService;
import com.atguigu.newstestdemo.vo.GetPageUserListVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public GetPageUserListVo selectAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> userList = userMapper.selectAll(pageNum, pageSize);
        PageInfo<User> pageInfo = new PageInfo<>(userList);

        GetPageUserListVo getPageUserListVo = new GetPageUserListVo();
        getPageUserListVo.setPageNum(pageInfo.getPageNum());
        getPageUserListVo.setPageSize(pageInfo.getPageSize());
        getPageUserListVo.setUserList(pageInfo.getList());
        getPageUserListVo.setTotal(pageInfo.getTotal());

        return getPageUserListVo;
    }

    @Override
    public void addUser(User user) {
        userMapper.insert(user);
    }

    @Override
    public void updateByPrimaryKey(User record) {
        userMapper.updateByPrimaryKey(record);
    }

    @Override
    public void deleteByPrimaryKey(Long id) {
        userMapper.deleteByPrimaryKey(id);
    }
}
